//
//  CommandExecuter.m
//  MusicAnalyzer
//
//  Created by jiro on 12/03/23.
//  Copyright 2012 jiro music. All rights reserved.
//

#import "CommandExecuter.h"

#import "../AppController.h"
#import "../StateSystem.h"
#import "../GUI/MusicSheetView.h"
#import "../GUI/GraphView.h"
 
static CommandExecuter* instance = nil;

static StateMachine* SM = nil;

@implementation CommandExecuter

@synthesize appController;

+ (id) sharedCommandExecuter
{
	if ( instance == nil )
	{	//	implicit call "+(id)allocWithZone:(NSZone *)zone"
		[ [self alloc ] init ];
	}
	return instance;
}

+ (id)allocWithZone:(NSZone *)zone
{
    @synchronized(self)
	{
        if ( instance == nil)
		{
            instance = [super allocWithZone:zone];
			SM = [ StateMachine sharedStateMachine ];
			return instance;
        }
    }
    return nil;
}

- (id)copyWithZone:(NSZone *)zone
{
    return self;
}
 
- (id)retain
{
    return self;
}
 
- (NSUInteger) retainCount
{
    return UINT_MAX;
}
 
- (void)release
{
}
 
- (id)autorelease
{
    return self;
}

- (void) activateGraphView: (Command*) command
{
	[ [ appController musicSheetView ] activate: NO ];
	[ [ appController graphView ] activate: YES ];
	[ [ appController chordTableView ] activate: NO ];
}

- (void) activateMusicSheetView: (Command*) command
{
	[ [ appController musicSheetView ] activate: YES ];
	[ [ appController graphView ] activate: NO ];
	[ [ appController chordTableView ] activate: NO ];
}

- (void) activateChordList: (Command*) command
{
	[ [ appController musicSheetView ] activate: NO ];
	[ [ appController graphView ] activate: NO ];
	[ [ appController chordTableView ] activate: YES ];
}

- (void) analyzeChordInclusion: (Command*) command
{
}

- (void) analyzeChordSequence: (Command*) command
{
}

- (void) analyzeChordType: (Command*) command
{
}

- (void) analyzeChordVoicing: (Command*) command
{
}

- (void) addChord: (Command*) command
{
}

- (void) modifyChord: (Command*) command
{
}

- (void) seleteChord: (Command*) command
{
}

- (void) setChordInBuffer: (Command*) command
{
}

- (void) addNoteInBuffer: (Command*) command
{
}

- (void) seleteNoteInBuffer: (Command*) command
{
}

- (void) deselectChord: (Command*) command
{
}

- (void) aelectChord: (Command*) command
{
}

- (void) executeCommand: (Command*) command
{
	NSLog( @"CommandExecuter - (void) executeCommand: (Command*) command, %@", command );

	switch ( [ command commandType ] )
	{
	case CommandType_ActivateGraphView:
		[ self activateGraphView: command ];
		return;

	case CommandType_ActivateMusicSheetView:
		[ self activateMusicSheetView: command ];
		return;

	case CommandType_ActivateChordTableView:
		[ self activateChordList: command ];
		return;

	case CommandType_AnalyzeChordInclusion:
	case CommandType_AnalyzeChordSequence:
	case CommandType_AnalyzeChordType:
	case CommandType_AnalyzeChordVoicing:


	case CommandType_AddChord:
	case CommandType_ModifyChord:
	case CommandType_DeleteChord:

	case CommandType_SetChordInBuffer:
	case CommandType_AddNoteInBuffer:
	case CommandType_DeleteNoteInBuffer:

	case CommandType_DeselectChord:
	case CommandType_SelectChord:
	default:
		break;
	}
}

- (void) undoExecuteCommand: (Command*) command
{
	switch ( [ command commandType ] )
	{
	case CommandType_ActivateGraphView:
	case CommandType_ActivateMusicSheetView:
	case CommandType_ActivateChordTableView:
	case CommandType_AnalyzeChordInclusion:
	case CommandType_AnalyzeChordSequence:
	case CommandType_AnalyzeChordType:
	case CommandType_AnalyzeChordVoicing:
	case CommandType_AddChord:
	case CommandType_ModifyChord:
	case CommandType_DeleteChord:
	case CommandType_SetChordInBuffer:
	case CommandType_AddNoteInBuffer:
	case CommandType_DeleteNoteInBuffer:
	case CommandType_DeselectChord:
	case CommandType_SelectChord:
	default:
		break;
	}
}

@end
